<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String id = (String) request.getAttribute("id");
%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
</head>
<body>

<div class="layui-fluid">
    <expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段"/>

    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto option-ba">

            <div class="layui-collapse ">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">展开搜索</h2>
                    <div class="layui-colla-content">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" name="productProductName" placeholder="输入商品名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <input type="text" name="productSn" placeholder="输入sn码" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <expect-x:zTree pickerId="productCategoryId" initKey="0" server="manager/productCategory/category.html"
                                                style="metroStyle" width="230" required="false"
                                                defaultVal="${productProduct.productCategoryId}"/>                            </div>
                            <div class="layui-inline">
                                <button  class="layui-btn" lay-submit lay-filter="Type-serch">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="productProductManage" lay-filter="productProductManage"></table>
            <script type="text/html" id="optionToolbar">
                <div class="layui-btn-container">
<%--                    <shiro:hasPermission name="Expect-X:system:type:create">--%>
                        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
<%--                    </shiro:hasPermission>--%>
<%--                    <shiro:hasPermission name="Expect-X:system:type:delete">--%>
                        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="dels" id="dels">批量删除</button>
<%--                    </shiro:hasPermission>--%>
                </div>
            </script>

            <script type="text/html" id="Logo">

                <div><img src="{{d.productProductLogo==null?'<%=basePath%>resources/images/noImage.jpg':d.productProductLogo}}" style="height: 28px" class="layui-table-link"></div>
            </script>
            <script type="text/html" id="gmtModifiedTpl">
                {{#
                var date = new Date();
                date.setTime(d.gmtModified);
                return date.Format("yyyy-MM-dd hh:mm:ss");
                }}
            </script>
            <script type="text/html" id="isDisabledTpl">
                <input type="checkbox" name="lock" value="{{d.id}}" title="禁用" lay-filter="isDisabledFilter" {{
                       d.isDisabled== 1 ? 'checked' : '' }}>
            </script>
            <script type="text/html" id="optionBar">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setTop">置顶</a>
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
            <script type="text/html" id="productImg">

                <div><img src="{{d.productImg==null?'<%=basePath%>resources/images/noImage.jpg':d.productImg}}" style="height: 28px" class="layui-table-link"></div>
            </script>
            <script type="text/html" id="productCategory">
                {{d.productCategory==null?'':d.productCategory.productCategoryName}}
            </script>
            <script type="text/html" id="attribute">
                <input type="checkbox" {{d.productIsBest==1?'checked':''}} disabled lay-skin="switch"  lay-text="精品|精品">
                <br>
                <input type="checkbox" {{d.productIsNew==1?'checked':''}} disabled lay-skin="switch" lay-text="新品|新品">
                <br>
                <input type="checkbox" {{d.productIsHot==1?'checked':''}} disabled  lay-skin="switch" lay-text="热销|热销" >
            </script>
            <script type="text/html" id="productMarketPriceTpl">
                <b style="color: red">￥{{d.productShopPrice}}</b> / ￥<s >{{d.productMarketPrice}}</s>
            </script>
        </div>
    </div>
</div>

<%@include file="../../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var id =<%=id%>;
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        table.render({
            elem: '#productProductManage',
            url: "<%=basePath%>manager/productProduct/page.html",
            toolbar: '#optionToolbar',
            cols: [[
                {type: 'checkbox'}
                , {field: 'id', width: 60, title: 'ID', sort: true}
                , {field: 'productImg', width: 90, title: '商品图片',templet:"#productImg"}
                , {field: 'productSn',width: 130,title: 'SN码' }
                , {field: 'productName',width: 450,title: '商品名称' }
                , {title: '商品分类',width: 100,templet:"#productCategory"}
                , {width: 150,title: '商品属性',templet:"#attribute" }
                , {field: 'productMarketPrice',width: 130,title: '价格',templet:"#productMarketPriceTpl" }
                , {field: 'productKeywords',width: 280,title: '商品关键词' }
                , {field: 'productClickCount',width: 100,title: '商品点击量'}
                , {field: 'gmtModified', width: 180,title: '更新时间', sort: true, templet: "#gmtModifiedTpl"}
                , {title: "操作", width: 180, align: "center",fixed:'right',  toolbar: "#optionBar"}
            ]],
            page: !0,
            limit: 10,
            height: "full-130",
            text: {none: "暂无相关数据"},
            response: {
                statusCode: 200
            }
        });
        //监听单元格编辑
        table.on('edit(productProductManage)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
        });
        table.on('toolbar(productProductManage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    var dialog = new UtilClass.LayerDialog({
                        title: '添加产品'
                        , content: "<%=basePath%>manager/productProduct/create.html"
                    });
                    dialog.layerShow();
                    break;

                case 'dels':
                    var data = checkStatus.data;

                    var List = JSON.stringify(data);
                    var jsList = JSON.parse(List);
                    if (jsList[0] == null) {
                        layer.msg('请选中至少一行');

                    } else {


                        var chars = new Array();
                        for (var li in jsList) {
                            chars[li] = jsList[li].id;
                        }
                        var str = "";
                        for (var i = 0; i < chars.length; i++) {
                            if (i == chars.length - 1) {
                                str += chars[i];
                            } else {
                                str = str + chars[i] + ",";
                            }

                        }
                        layer.load(2);
                        $.ajax({
                            type: "get",
                            url: "<%=basePath%>manager/productProduct/delete/" + str + ".html",
                            success: function (data) {
                                layer.closeAll("loading");
                                data = JSON.parse(data);
                                if (data.success) {
                                    layer.msg("删除成功",{time:1000});
                                    table.reload('productProductManage');
                                } else {
                                    layer.msg(data.message, {icon: 5});
                                }
                            }
                        });
                        break;
                    }
            }
            ;
        });
        table.on("tool(productProductManage)", function (e) {
            console.log(e.data);
            if ("del" === e.event) {
                layer.confirm("真的删除行么", function (t) {
                    layer.close(t);

                    var List = JSON.stringify(e.data);
                    var jsList = JSON.parse(List);
                    var ids = jsList.id;
                    layer.load(2);
                    $.ajax({
                        type: "get",
                        url: "<%=basePath%>manager/productProduct/delete/" + ids + ".html",
                        success: function (data) {
                            layer.closeAll("loading");
                            data = JSON.parse(data);
                            if (data.success) {
                                layer.msg("删除成功",{time:1000});
                                table.reload('productProductManage');
                            } else {
                                layer.msg(data.message, {icon: 5});
                            }
                        }
                    });

                })
            } else if ("edit" === e.event) {
                var dialog = new UtilClass.LayerDialog({
                    title: "编辑[" + e.data.productName + "]",
                    content: "<%=basePath%>manager/productProduct/update/" + e.data.id + ".html",
                });
                dialog.layerShow();
                $(e.tr);
            }else if ("setTop" === e.event) {
                layer.load(2);
                $.ajax({
                    type: "get",
                    url: "<%=basePath%>manager/productProduct/setTop/" + e.data.id + ".html",
                    success: function (data) {
                        layer.closeAll("loading");
                        data = JSON.parse(data);
                        if (data.success) {
                            layer.msg("置顶成功",{time:1000});
                            table.reload('productProductManage');
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        });

        //监听搜索
        form.on('submit(Type-serch)', function (data) {
            var field = data.field;
            $(".layui-laypage-skip").find("input").val("1");
            $(".layui-laypage-btn").click();
            table.reload('productProductManage', {
                where: {"productProductName":field.productProductName,"productSn":field.productSn,"productCategoryId":field.productCategoryId}
            });
        });
        //监听锁定操作
        form.on('checkbox(isDisabledFilter)', function (obj) {
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
        });

    });

    function edit(e) {

    }

</script>
</body>
</html>

